package com.cmes.core.json;

import com.cmes.core.utils.dict.Dict;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * 字典序列化
 *
 * @author Bruce.Gong
 * @since 1.0.0-SNAPSHOT
 */
public class DictSerializer extends JsonSerializer<Object> {

    @SuppressWarnings("rawtypes")
    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        if (value instanceof Dict) {
            gen.writeString(((Dict) value).getCode().toString());
        } else {
            gen.writeString(value.toString());
        }
    }

}
